package C50;

import java.util.Arrays;

/**
 * ClassName: C06
 * Package: C50
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/28 12:08
 * @Version 1.0
 * @Since 1.0
 */
public class C06 {
    public static void main(String[] args) {
        int[] arr = {1,1,1,1,1,1,999,999,999,999,999};
        int[] arr2 = {499,500,501};
        System.out.println(findRadius(arr, arr2));

    }
    public static int findRadius(int[] houses, int[] heaters) {
        Arrays.sort(houses);
        Arrays.sort(heaters);
        int ans = 0;
        for (int i = 0, j = 0; i < houses.length; i++) {
            while(!best(houses, heaters, i, j)) {
                j ++;
            }
            ans = Math.max(Math.abs(houses[i] - heaters[j]), ans);
        }
        return ans;
    }

    private static boolean best(int[] houses, int[] heaters, int i, int j) {
        return j == heaters.length - 1 || Math.abs(houses[i] - heaters[j]) < Math.abs(houses[i] - heaters[j + 1]);
    }

}
